import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { Material } from "@/pages/base/material/entity";

interface SingleMaterialSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedMaterial?: Material) => void;
}

const SingleMaterialSelector:React.FC<SingleMaterialSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的物料
  const [selectedMaterial, setSelectedMaterial] = useState<Material>();

  const handleOk = () => {
		onOk(selectedMaterial);
	};

	return (
		<Modal title="选择物料" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="material_seach_report"
        selectionType={SelectionType.RADIO}
        onSelectChange={(selectedRows) => {setSelectedMaterial(selectedRows[0])}}  
      />
		</Modal>
	);
}

export default SingleMaterialSelector;